<?php

namespace common\models\bi;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\bi\HrOrgFlat;

/**
 * HrOrgFlatSearch represents the model behind the search form of `common\models\bi\HrOrgFlat`.
 */
class HrOrgFlatSearch extends HrOrgFlat
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['HOF_COMPANY_ID', 'HOF_PARENT_ID', 'HOF_STARTDATE', 'HOF_UPDATE', 'HOF_CREATED_AT', 'HOF_UPDATED_AT'], 'safe'],
            [['HOF_ORG_LEVEL'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = HrOrgFlat::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'HOF_ORG_LEVEL' => $this->HOF_ORG_LEVEL,
            'HOF_STARTDATE' => $this->HOF_STARTDATE,
            'HOF_UPDATE' => $this->HOF_UPDATE,
            'HOF_CREATED_AT' => $this->HOF_CREATED_AT,
            'HOF_UPDATED_AT' => $this->HOF_UPDATED_AT,
        ]);

        $query->andFilterWhere(['like', 'HOF_COMPANY_ID', $this->HOF_COMPANY_ID])
            ->andFilterWhere(['like', 'HOF_PARENT_ID', $this->HOF_PARENT_ID]);

        return $dataProvider;
    }
}
